{extend name="public/base" /}

{block name="content"}
<div class="container my-3 my-md-4">
    <div class="row">
        <div class="col-lg-4">
            {include file="public/sidenav" /}
        </div>
        <div class="col-lg-8 mt-3 mt-lg-0">
            <form id="profile-form" method="post">
                {:token()}
                <input type="hidden" name="id" value="{$info.id}">
            <div class="card">
                <div class="card-header">
                    <strong>个人资料</strong>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input class="form-control" name="username" id="username" type="text" value="{$info.username}" placeholder="输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="mobile">手机号</label>
                        <input class="form-control" name="mobile" id="mobile" type="tel" value="{$info.mobile}" placeholder="输入手机号">
                    </div>
                    <div class="form-group">
                        <label for="email">邮箱</label>
                        <input class="form-control" name="email" id="email" type="text" value="{$info.email}" disabled>
                    </div>
                </div>
                <div class="card-footer">
                    <button class="btn btn-success" type="button" id="sub">确定</button>
                    <button class="btn btn-secondary" type="reset">重置</button>
                </div>
            </div>
            </form>
        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>

    toastr.options = {
        "closeButton": true,
        //"progressBar": true,
        "positionClass": "toast-top-center",
        "timeOut": "1500"
    };

    $('#sub').on('click',function () {
        $.ajax({
            type: 'post',
            url: "{:url('User/profileDo')}",
            data: $('#profile-form').serialize(),
            dataType: 'json',
            success: function (data) {
                switch (data.status) {
                    case 1:
                        $('input[name="username"]').val(data.message.username);
                        $('input[name="mobile"]').val(data.message.mobile);
                        $('input[name="__token__"]').val(data.token);
                        toastr.success('更新成功');
                        break;
                    case 0:
                    case -1:
                        $('input[name="__token__"]').val(data.token);
                        toastr.warning(data.message);
                }
            }
        })
    })
</script>
{/block}